
import java.util.Random;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author zz
 */
public class Myapp {
    public static void main(String[] args) {
        int n=0,m=0;
        float L=0;
        System.out.printf("输入你想做的题数：");
        Scanner sc =new Scanner(System.in);
        n=sc.nextInt(); 
        m=n;
        while(n>0){
            Random ra = new Random();
            float rank=ra.nextInt(2);
            if (rank>0.5){
            if (fen()==1){
                L++;
            }
            }
            if (rank<=0.5){
            if (zheng()==1){
                L++;
            }
            }
            n--;
        }
        L=L/m*100;
        System.out.printf("你的正确率是"+L);
        System.out.println("%");
    }
    public static int fen(){
        int n=0,num=0;
        String ans="";
        Random ra = new Random();
        Random shu = new Random();
        n=ra.nextInt(4)+1;
        int a,b,c,d;
        a=shu.nextInt(10)+1;
        b=shu.nextInt(10)+1;
        c=shu.nextInt(10)+1;
        d=shu.nextInt(10)+1;
        if(0<n&n<=1){//+
            ans=jia(a,b,c,d);
            if(a%b==0)
                System.out.printf("%d+",a/b);
            else
            System.out.printf("%d"+"/"+"%d+",a,b);
            if(c%d==0)
                System.out.printf("%d=",c/d);
            else
            System.out.printf("%d"+"/"+"%d=",c,d);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        if(1<n&n<=2){//-
            ans=jian(a,b,c,d);
            if(a%b==0)
                System.out.printf("%d-",a/b);
            else
            System.out.printf("%d"+"/"+"%d-",a,b);
            if(c%d==0)
                System.out.printf("%d=",c/d);
            else
            System.out.printf("%d"+"/"+"%d=",c,d);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        if(2<n&n<=3){//x
            ans=cheng(a,b,c,d);
            if(a%b==0)
                System.out.printf("%d×",a/b);
            else
            System.out.printf("%d"+"/"+"%d×",a,b);
            if(c%d==0)
                System.out.printf("%d=",c/d);
            else
            System.out.printf("%d"+"/"+"%d=",c,d);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        if(3<n&n<=4){//÷
            ans=chu(a,b,c,d);
            if(a%b==0)
                System.out.printf("%d÷",a/b);
            else
            System.out.printf("%d"+"/"+"%d÷",a,b);
            if(c%d==0)
                System.out.printf("%d=",c/d);
            else
            System.out.printf("%d"+"/"+"%d=",c,d);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        return num;
    }
    public static int zheng(){
        int n=0,num=0;
        String ans=" ";
        Random ra = new Random();
        Random shu = new Random();
        n=ra.nextInt(4)+1;
        int a,b;
        a=shu.nextInt(10)+1;
        b=shu.nextInt(10)+1;

        if(0<n&n<=1){//+
            ans=jia(a,1,b,1);
            System.out.printf("%d"+"+"+"%d=",a,b);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        if(1<n&n<=2){//-
            ans=jian(a,1,b,1);
            System.out.printf("%d"+"-"+"%d=",a,b);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        if(2<n&n<=3){//x
            ans=cheng(a,1,b,1);
            System.out.printf("%d"+"×"+"%d=",a,b);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        if(3<n&n<=4){//÷
            ans=chu(a,1,b,1);
            System.out.printf("%d"+"÷"+"%d=",a,b);
            Scanner sc =new Scanner(System.in);
            String youRans = sc.next();
            if (ans.equals(youRans)){
                System.out.printf("回答正确\n");num=1;
            }
            else
            System.out.printf("正确答案："+ans+"\n");
        }
        return num;
    }

    private static String jia(int a, int b, int c, int d) {
        String ans=" ";
        int ans1=a*d+b*c;
        int ans2=b*d;
        int Max=0;
        for(int i=ans1;i>=1;i--){
            if(ans1%i==0&&ans2%i==0)
            {
                Max = i;
            break;
            }
        }
        if(ans1%ans2==0){
            ans=ans1/ans2+"";
        }else{
            ans=(ans1/Max)+"/"+(ans2/Max);
        }
        return ans;
    }
    private static String jian(int a, int b, int c, int d) {
        String ans=" ";
        int ans1=a*d-b*c;
        int ans2=b*d;
        int Max=0,Z=0;
        if(ans1==0){
            ans ="0";
            return ans;
        }
        if(ans1<0){
            ans1=-ans1;
            Z=1;
        }
        for(int i=ans1;i>=1;i--){
            if(ans1%i==0&&ans2%i==0)
            {
                Max = i;
            break;
            }
        }
        if(ans1%ans2==0){
            ans=ans1/ans2+"";
        }else {
                ans=(ans1/Max)+"/"+(ans2/Max); 
        }
        if(Z==1){
            ans="-"+ans;
            return ans;
        }
        return ans;
    }
        private static String cheng(int a, int b, int c, int d) {
        String ans=" ";
        int ans1=a*c;
        int ans2=b*d;
        int Max=0;
        for(int i=ans1;i>=1;i--){
            if(ans1%i==0&&ans2%i==0)
            {
                Max = i;
            break;
            }
        }
        if(ans1%ans2==0){
            ans=ans1/ans2+"";
        }else{
            ans=(ans1/Max)+"/"+(ans2/Max);
        }
        return ans;
    }
    private static String chu(int a, int b, int c, int d) {
        String ans=" ";
        int ans1=a*d;
        int ans2=c*b;
        int Max=0;
        for(int i=ans1;i>=1;i--){
            if(ans1%i==0&&ans2%i==0)
            {
                Max = i;
            break;
            }
        }
        if(ans1%ans2==0){
            ans=ans1/ans2+"";
        }else{
            ans=(ans1/Max)+"/"+(ans2/Max);
        }
        return ans;
    }

}
